package com.example.leetcode.niuke;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class NiuKe3 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int i = scanner.nextInt();
//        while (scanner.hasNextLine()) {
//            String s = scanner.nextLine();
//        }
        System.out.println(getK(s,i));
    }


    private static int getK(String s ,int k) {
        if (s.length() == 1) {
            return 1;
        }
        int count = 1;
        char last = s.charAt(0);
        int[] ints = new int[26];
        for (int i = 1;i<s.length();i++) {
            if (s.charAt(i) == last) {
                count++;
            }else {
                int anInt = ints[last - 'A'];
                if (count > anInt) {
                    ints[last - 'A'] = count;
                }
                last = s.charAt(i);
                count = 1;
            }
        }
        int anInt = ints[last - 'A'];
        if (count > anInt) {
            ints[last - 'A'] = count;
        }
        Arrays.sort(ints);
        int index = 25;
        while (k -1 > 0) {
            index--;
            k--;
        }
        return ints[index];
    }

}
